package com.cup.newSecurity.serviceImpl;

import org.junit.Assert;

import com.cup.common.base.BaseLocalException;

public class BaseLocalExceptionAssert {
	public static void assertException(String expectedErrorCode,
			ExceptionCallback callback) {
		assertException(expectedErrorCode, callback, "");
	}

	public static void assertException(String expectedErrorCode,
			ExceptionCallback callback, String msg) {
		try {
			callback.execute();
		} catch (BaseLocalException e) {
			Assert.assertEquals(msg, expectedErrorCode, e.getErrorCode());
		}
	}

	public static void assertNoException(ExceptionCallback callback) {
		assertNoException(callback, "");
	}

	public static void assertNoException(ExceptionCallback callback, String msg) {
		try {
			callback.execute();
		} catch (BaseLocalException e) {
			Assert.fail("Should not raise exception." + "\n" + msg);
		}
	}
}
